<%@ page import="com.wbi.util.Util" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<%
    String pdrq = Util.null2String(request.getParameter("pdrq"));
    JSONArray dataList = new JSONArray();
    RecordSet rs = new RecordSet();
    try {
        //查询库存
        rs.executeQuery("select * from uf_stypkc where kc>0");
        while (rs.next()) {
            String mc = Util.null2String(rs.getString("mc"));
            String mcwb = Util.null2String(rs.getString("mcwb"));
            int kc = Util.getIntValue(rs.getString("kc"), 0);
            int rksl = getRksl(mc, pdrq);
            int ffsl = getFfsl(mc, pdrq);
            int sjkc = kc + ffsl - rksl;
            if (sjkc > 0) {
                JSONObject json = new JSONObject();
                json.put("mc", mc);
                json.put("mcwb", mcwb);
                json.put("kc", sjkc);
                dataList.add(json);
            }
        }
        out.println(dataList);
    } catch (Exception e) {
        out.println(e);
    }
%>
<%!

    public static int getRksl(String mc, String rq) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select sum(sl) sl from  uf_styprktz where wpmc=? and rksj >?", mc, rq + " 24:00");
        rs.next();
        return Util.getIntValue(rs.getString("sl"), 0);
    }

    public static int getFfsl(String mc, String rq) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select sum(sl) sl from  uf_stypfftz where wpmc=? and ffsj >?", mc, rq + " 24:00");
        rs.next();
        return Util.getIntValue(rs.getString("sl"), 0);
    }

%>